//
//  ViewController.m
//  CatSport
//
//  Created by yonghui liu on 2020/5/13.
//  Copyright © 2020 刘永慧. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Category.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
//    [self createScrollView];
//    [self createButton];
//    [self attributeString];

}

- (void)createScrollView {
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    //设置背景颜色
    scrollView.backgroundColor = [UIColor grayColor];
    //设置包含的内容尺寸
    scrollView.contentSize = CGSizeMake(self.view.width, self.view.height*5);
    //设置偏移量
    scrollView.contentOffset = CGPointMake(0, 30);
    scrollView.delegate = self;
    //内容视图边缘嵌入的间距
    scrollView.contentInset = UIEdgeInsetsMake(-10, 10, 10, 10);
    //弹簧效果
    scrollView.bounces = NO;
    //垂直方向弹簧效果
    scrollView.alwaysBounceVertical = YES;
    //水平方向弹簧效果
    scrollView.alwaysBounceHorizontal = NO;
    //减速速度 值越小减速停止的时间越短
    scrollView.decelerationRate = 0.1;
    //只在一个方向上滚动
    scrollView.directionalLockEnabled = YES;
    //是否能滚动
    scrollView.scrollEnabled = YES;
    // 默认为YES，设置为NO点击转态栏不能滑动到顶部
    scrollView.scrollsToTop = YES;
    // 默认为NO，设置YES内容视图整页滚动
    scrollView.pagingEnabled = YES;
    //隐藏键盘样式
    scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    //滚动条样式
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    
    //隐藏、显示滚动条
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    //滚动条位置
    scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(30, 30, 0, 0);
    
    //缩放比例
    scrollView.zoomScale = 1.5f;
    scrollView.minimumZoomScale = 0.5f;
    scrollView.maximumZoomScale = 3.0f;
    //缩放反弹
    scrollView.bouncesZoom = NO;
    
    self.scrollView = scrollView;
    [self.view addSubview:scrollView];
}




- (void)attributeString {
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:@"这是一个富文本字符串"];
    //字体
    [attriString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30.0f] range:NSMakeRange(4, 3)];
    //颜色
    [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 4)];
    //背景
    [attriString addAttribute:NSBackgroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(7, 3)];
    //描边颜色
    [attriString addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(4, 3)];
    //
    [attriString addAttribute:NSStrokeWidthAttributeName value:@1.5 range:NSMakeRange(4, 3)];
    //文字倾斜
    [attriString addAttribute:NSObliquenessAttributeName value:@(0.5f) range:NSMakeRange(4, 3)];
    
    //特效
    [attriString addAttribute:NSTextEffectAttributeName value:NSTextEffectLetterpressStyle range:NSMakeRange(4, 3)];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, self.view.width, 60)];
    label.attributedText = attriString;
    label.textAlignment = NSTextAlignmentCenter;
    [self.scrollView addSubview:label];
}

// MARK: ~~~~~~~~跳转到设置
- (void)createButton {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(100, 100, 100, 80);
    btn.backgroundColor = [UIColor purpleColor];
    [btn addTarget:self action:@selector(openSetting:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:btn];
}

- (void)openSetting:(UIButton *)btn {
    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
        }];
    }
}

// MARK: ~~~~~~~~ scrollViewDelegate
// 滑动时多次调用，offset值改变即滑动过程中，便会调用该代理函数
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
}

// 缩放时多次调用，zoomScale值改变即缩放过程中，便会调用该函数
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    
}

// 开始滑动时调用，只调用一次，手指不松开只算一次
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    
}

// 结束滑动时调用，只调用一次，手指离开时执行
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0) {
    
}

// 已经结束滚动时调用，只调用一次，当手指离开达成时执行
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    
}


// 开始减速时调用，只调用一次，当内容视图开始减速状态执行
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    
}

// 结束减速时调用，只调用一次，当内容视图结束减速状态执行
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
}


// 滚动动画结束时调用，没有动画则不调用
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    
}


// 返回将要缩放的UIView对象，调用多次
- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 20, self.view.width, 80)];
    view.backgroundColor = [UIColor blueColor];
    return view;
}

// 开始缩放时调用，只调用一次
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view NS_AVAILABLE_IOS(3_2) {
    
}

// 已经结束缩放时调用，只调用一次
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale {
    
}


// 当用户点击状态栏内容视图是否滚动到顶部
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
    return YES;
}

// 滚动到顶部时调用
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
    
}



@end
